#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.

"""

"""


class Solution:
    def mergeSortedArray(self, A, B):
        return self._common_mergeSortedArray(A, B)

    def _common_mergeSortedArray(self, A, B):
        # TODO: 一个很长,一个很短, 如何优化
        # print(len(A) / len(B))
        # print(A)
        ratio_threshold = 10
        ratio = len(A) / len(B)
        if ratio < 1/ratio_threshold  or ratio > ratio_threshold:
            print('len diff large')
            return

        results = []

        idx_a = 0
        idx_b = 0
        len_a = len(A)
        len_b = len(B)
        while idx_a < len_a and idx_b < len_b:
            if A[idx_a] < B[idx_b]:
                results.append(A[idx_a])
                idx_a += 1
            else:
                results.append(B[idx_b])
                idx_b += 1

        assert not(idx_a != len_a and idx_b != len_b)
        if idx_a != len_a:
            results += A[idx_a:]
        if idx_b != len_b:
            results += B[idx_b:]

        return results

    def _dis_large_little(self, A, B):
        pass


def main():
    print("start main")

    s = Solution()
    r = s.mergeSortedArray([1,2,3], [2,3,5])
    r = s.mergeSortedArray([3], [2,3,5])
    print(r)

if __name__ == "__main__":
    main()
